package com.ssyx.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssyx.common.result.Result;
import com.ssyx.model.product.AttrGroup;
import com.ssyx.product.service.AttrGroupService;
import com.ssyx.vo.product.AttrGroupQueryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:AttrGroupController
 * Description:
 *
 * @Author kay
 * @Create 2024/4/28 11:25
 * @Version 1.0
 */
@Tag(name = "平台属性分组管理")
@RestController
@RequestMapping("/admin/product/attrGroup")
//@CrossOrigin
public class AttrGroupController {

    @Autowired
    private AttrGroupService attrGroupService;

    @Operation(summary = "平台属性分组列表")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page,
                        @PathVariable Long limit,
                        AttrGroupQueryVo attrGroupQueryVo){
        Page<AttrGroup> pageParams = new Page<>(page,limit);
        IPage<AttrGroup> pageModel = attrGroupService.getPage(pageParams,attrGroupQueryVo);
        return Result.ok(pageModel);
    }

    @Operation(summary = "获取")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        AttrGroup attrGroup = attrGroupService.getById(id);
        return Result.ok(attrGroup);
    }

    @Operation(summary = "新增")
    @PostMapping("save")
    public Result save(@RequestBody AttrGroup attrGroup) {
        attrGroupService.save(attrGroup);
        return Result.ok(null);
    }

    @Operation(summary = "修改")
    @PutMapping("update")
    public Result updateById(@RequestBody AttrGroup attrGroup) {
        attrGroupService.updateById(attrGroup);
        return Result.ok(null);
    }

    @Operation(summary = "删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        attrGroupService.removeById(id);
        return Result.ok(null);
    }

    @Operation(summary = "根据id列表删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        attrGroupService.removeByIds(idList);
        return Result.ok(null);
    }


    @Operation(summary = "获取全部属性分组")
    @GetMapping("findAllList")
    public Result findAllList() {
        List<AttrGroup> attrGroupList = attrGroupService.list();
        return Result.ok(attrGroupList);
    }

}
